<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>




<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>表单组合</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${ctxPath}/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${ctxPath}/layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">新增用户</div>
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="component-form-group">
          
          <div class="layui-col-md6">
	          <div class="layui-form-item">
	            <label class="layui-form-label">用户账号</label>
	            <div class="layui-input-inline">
	              <input type="text" name="account" lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
	            </div>
	          </div>
          </div>
          <div class="layui-col-md6">
	          <div class="layui-form-item">
	            <label class="layui-form-label">用户名称</label>
	            <div class="layui-input-inline">
	              <input type="text" name="nickName" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
	            </div>
	          </div>
          </div>
          <div class="layui-col-md6">
	          <div class="layui-form-item">
	            <label class="layui-form-label">设置密码</label>
	            <div class="layui-input-inline">
	              <input id="password" type="password" name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
	            </div>
	            <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
	          </div>
          </div>
          <div class="layui-col-md6">
	          <div class="layui-form-item">
	            <label class="layui-form-label">确认密码</label>
	            <div class="layui-input-inline">
	              <input type="password" name="repassword" lay-verify="repass" placeholder="请重复密码" autocomplete="off" class="layui-input">
	            </div>
	            <div class="layui-form-mid layui-word-aux">请重复输入密码</div>
	          </div>
          </div>
          <div class="layui-col-md6">
	          <div class="layui-form-item">
	            <label class="layui-form-label">工号</label>
	            <div class="layui-input-inline">
	              <input type="text" name="no" lay-verify="required" placeholder="请输入工号" autocomplete="off" class="layui-input">
	            </div>
	          </div>
          </div>
          <div class="layui-col-md6">
	          <div class="layui-form-item">
	            <div class="layui-inline">
	              <label class="layui-form-label">用户角色</label>
	              <div class="layui-input-inline">
	                <select name="roleId" lay-verify="required" lay-search="">
	                  <option value="">直接选择或搜索选择</option>
	                  <option value="1">酒店经理</option>
	                  <option value="2">酒店前台</option>
	                  <option value="3">保洁人员</option>
	                  <option value="4">维修人员</option>
	                  <option value="5">后勤人员</option>
	                  <option value="6">公司财务</option>
	                </select>
	              </div>
	            </div>
	          </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
              <input type="radio" name="sex" value="男" title="男" checked="">
              <input type="radio" name="sex" value="女" title="女">
            </div>
          </div>     
          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>

    
  <script src="${ctxPath}/layuiadmin/layui/layui.js"></script>  
  <script src="${ctxPath}/js/jquery-1.11.1.min.js"></script>
  <script>
  layui.config({
    base: '${ctxPath}/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'laydate'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,element = layui.element
    ,layer = layui.layer
    ,laydate = layui.laydate
    ,form = layui.form;
    
    form.render(null, 'component-form-group');

    laydate.render({
      elem: '#LAY-component-form-group-date'
    });
    
    /* 自定义验证规则 */
    form.verify({
      pass: [/(.+){3,16}$/, '密码必须3到16位']
      ,repass: function(value){
    	  if(value!=$("#password").val()){
    		  console.log(value);
    		  return '密码不一致';
    	  }
      }
    });
    
    /* 监听提交 */
    form.on('submit(component-form-demo1)', function(data){
      /* parent.layer.alert(JSON.stringify(data.field), {
        title: '最终的提交信息'
      }) */
	$.ajax(
		{
			url:'${ctxPath}/User/saveUser',
			type:'post',
			dataType:'json',
			data:data.field,
			success:function( data ){
				if( data.result!='success' ){
					layer.msg( data.cause ,
							{icon:2,time:2000,offset:'20px'});
				}else{
					layer.msg( '注册成功' ,
							{icon:1,time:2000,offset:'20px'});
				}
			}
		}			
	);
      return false;
    });
  });
  </script>
</body>
</html>
